
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>高级二维码生成器</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
   <script src="https://cdn.bootcdn.net/ajax/libs/qrcodejs/1.0.0/qrcode.js"></script>
    <style>
        :root {
            --primary: #6366f1;
            --secondary: #8b5cf6;
            --dark: #1e293b;
            --light: #f8fafc;
        }
        body {
            font-family: 'Segoe UI', sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }
        .container {
            background: white;
            border-radius: 16px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
            padding: 30px;
            width: 100%;
            max-width: 600px;
        }
        .title {
            color: var(--dark);
            text-align: center;
            margin-bottom: 24px;
            font-weight: 600;
        }
        .input-group {
            margin-bottom: 20px;
        }
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: var(--dark);
        }
        input, select {
            width: 100%;
            padding: 12px 15px;
            border: 1px solid #e2e8f0;
            border-radius: 8px;
            font-size: 16px;
            transition: all 0.3s;
        }
        input:focus, select:focus {
            outline: none;
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
        }
        .color-picker {
            display: flex;
            gap: 15px;
            margin-top: 15px;
        }
        .color-option {
            flex: 1;
        }
        .preview-container {
            display: flex;
            justify-content: center;
            margin: 30px 0;
            min-height: 300px;
            align-items: center;
        }
        #qrcode {
            transition: all 0.3s;
            border-radius: 12px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.1);
        }
        .btn {
            background: linear-gradient(to right, var(--primary), var(--secondary));
            color: white;
            border: none;
            padding: 12px 24px;
            border-radius: 8px;
            font-size: 16px;
            font-weight: 500;
            cursor: pointer;
            width: 100%;
            transition: all 0.3s;
        }
        .btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(99, 102, 241, 0.3);
        }
        .presets {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 10px;
            margin-bottom: 20px;
        }
        .preset-btn {
            padding: 8px;
            border-radius: 6px;
            border: 1px solid #e2e8f0;
            background: white;
            cursor: pointer;
            transition: all 0.2s;
        }
        .preset-btn:hover {
            border-color: var(--primary);
        }
    </style>
</head>
<body>
    <div class="container">
        <h1 class="title">高级二维码生成器</h1>
        
        <div class="input-group">
            <label for="text">二维码内容</label>
            <input type="text" id="text" placeholder="输入文本或URL" value="https://www.baidu.com">
        </div>

        <div class="presets">
            <button class="preset-btn" data-preset="gradient">渐变风格</button>
            <button class="preset-btn" data-preset="dark">暗黑模式</button>
            <button class="preset-btn" data-preset="vintage">复古风格</button>
        </div>

        <div class="input-group">
            <label for="size">二维码尺寸</label>
            <input type="range" id="size" min="100" max="500" value="200">
            <span id="size-value">200px</span>
        </div>

        <div class="color-picker">
            <div class="color-option">
                <label for="colorDark">前景色</label>
                <input type="color" id="colorDark" value="#000000">
            </div>
            <div class="color-option">
                <label for="colorLight">背景色</label>
                <input type="color" id="colorLight" value="#ffffff">
            </div>
        </div>

        <div class="input-group">
            <label for="correctLevel">容错级别</label>
            <select id="correctLevel">
                <option value="L">低 (7%)</option>
                <option value="M" selected>中 (15%)</option>
                <option value="Q">高 (25%)</option>
                <option value="H">最高 (30%)</option>
            </select>
        </div>

        <div class="preview-container">
            <div id="qrcode"></div>
        </div>

        <button id="generate" class="btn">生成二维码</button>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const textInput = document.getElementById('text');
            const sizeInput = document.getElementById('size');
            const sizeValue = document.getElementById('size-value');
            const colorDarkInput = document.getElementById('colorDark');
            const colorLightInput = document.getElementById('colorLight');
            const correctLevelInput = document.getElementById('correctLevel');
            const generateBtn = document.getElementById('generate');
            const presetBtns = document.querySelectorAll('.preset-btn');
            
            let qrcode = null;

            // 更新尺寸显示
            sizeInput.addEventListener('input', function() {
                sizeValue.textContent = `${this.value}px`;
            });

            // 预设配置
            const presets = {
                gradient: {
                    colorDark: '#8b5cf6',
                    colorLight: '#f8fafc'
                },
                dark: {
                    colorDark: '#f8fafc',
                    colorLight: '#1e293b'
                },
                vintage: {
                    colorDark: '#78350f',
                    colorLight: '#fef3c7'
                }
            };

            presetBtns.forEach(btn => {
                btn.addEventListener('click', function() {
                    const preset = presets[this.dataset.preset];
                    colorDarkInput.value = preset.colorDark;
                    colorLightInput.value = preset.colorLight;
                    generateQRCode();
                });
            });

            // 生成二维码
            function generateQRCode() {
                const options = {
                    text: textInput.value,
                    width: parseInt(sizeInput.value),
                    height: parseInt(sizeInput.value),
                    colorDark: colorDarkInput.value,
                    colorLight: colorLightInput.value,
                    correctLevel: QRCode.CorrectLevel[correctLevelInput.value]
                };

                document.getElementById('qrcode').innerHTML = '';
                qrcode = new QRCode(document.getElementById('qrcode'), options);
            }

            // 初始生成
            generateQRCode();

            // 事件监听
            generateBtn.addEventListener('click', generateQRCode);
            textInput.addEventListener('keypress', function(e) {
                if (e.key === 'Enter') generateQRCode();
            });
        });
    </script>
</body>
</html>
